local exists = redis.pcall("EXISTS", KEYS[1])
if 0 == exists then
    local today = redis.pcall("TIME")
    redis.pcall("HSET", KEYS[1], "cur", 1)
    redis.pcall("HSET", KEYS[1], "date", KEYS[2])
    return 1
end

local maxSeqNum = 900000000
if "1" == KEYS[3] then
    redis.pcall("HSET", KEYS[1], "cur", 1)
    redis.pcall("HSET", KEYS[1], "date", KEYS[2])
    return 1
end

local seqNum = redis.pcall("HINCRBY", KEYS[1], "cur", 1)
if seqNum <= maxSeqNum then
    return seqNum
else
    return nil
end